package org.jeecg.modules.front.util;

import com.wechat.pay.java.core.Config;
import lombok.Data;

/** Native 支付下单为例 */
@Data
public class WechatUtil {

    /** 商户号 */
    private static String merchantId;
    /** 商户API私钥路径 */
    private static String privateKeyPath;
    /** 商户证书序列号 */
    private static String merchantSerialNumber;
    /** 商户APIV3密钥 */
    private static String apiV3key;
    /** APPID */
    private static String appId;
    /** 回调域名 */
    private static String notifyUrl;
    /** 配置实体 */
    private static Config config;


    public static String getMerchantId() {
        return merchantId;
    }
    public static String getPrivateKeyPath() {
        return privateKeyPath;
    }
    public static String getMerchantSerialNumber() {
        return merchantSerialNumber;
    }
    public static String getApiV3key() {
        return apiV3key;
    }
    public static String getAppId() {
        return appId;
    }
    public static String getNotifyUrl() {
        return notifyUrl;
    }
    public static Config getConfig() {
        return config;
    }
    public static void setMerchantId(String merchantId) {
        WechatUtil.merchantId = merchantId;
    }
    public static void setPrivateKeyPath(String privateKeyPath) {
        WechatUtil.privateKeyPath = privateKeyPath;
    }
    public static void setMerchantSerialNumber(String merchantSerialNumber) {
        WechatUtil.merchantSerialNumber = merchantSerialNumber;
    }
    public static void setApiV3key(String apiV3key) {
        WechatUtil.apiV3key = apiV3key;
    }
    public static void setAppId(String appId) {
        WechatUtil.appId = appId;
    }
    public static void setNotifyUrl(String notifyUrl) {
        WechatUtil.notifyUrl = notifyUrl;
    }
    public static void setConfig(Config config) {
        WechatUtil.config = config;
    }



//    public PrepayResponse buyOrder(UserhomeOrder userhomeOrder, Good good) throws InstantiationException, IllegalAccessException {
//        Config config = wechatConfigUtil.getConfig();
//        // 构建service
//        NativePayService service = new NativePayService.Builder().config(config).build();
//        // request.setXxx(val)设置所需参数，具体参数可见Request定义
//        PrepayRequest request = new PrepayRequest();
//        Amount amount = new Amount();
//        amount.setTotal((int) (userhomeOrder.getTprice()*100));
//        request.setAmount(amount);
//        request.setAppid(wechatConfigUtil.getAppId());
//        request.setMchid(wechatConfigUtil.getMerchantId());
//        request.setDescription(good.getName()+"*"+userhomeOrder.getNum());
//        request.setNotifyUrl(wechatConfigUtil.getNotifyUrl()+"front/order/wx/notify");
//        request.setOutTradeNo(userhomeOrder.getOrderNum());
//        // 调用下单方法，得到应答
//        // 使用微信扫描 code_url 对应的二维码，即可体验Native支付
//        return service.prepay(request);
//    }
}
